﻿<Window x:Class="FarpacHelper.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:System="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:FarpacHelper"
        xmlns:dnd="clr-namespace:GongSolutions.Wpf.DragDrop;assembly=GongSolutions.Wpf.DragDrop"
        Title="Farpac Helper" Height="621" Width="612" FontWeight="Bold" Topmost="True" Closed="Window_Closed" Name="Main" Loaded="Main_Loaded">
    <Window.Resources>
        <Style TargetType="ListBox">
            <Setter Property="Height" Value="300" />
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        </Style>

        <DataTemplate x:Key="ToolstringTemplate">
            <DataTemplate.Resources>
                <Style TargetType="Image">
                    <Setter Property="Width" Value="Auto" />
                    <Setter Property="Height" Value="Auto" />
                    <Setter Property="Margin" Value="0" />
                    <Setter Property="HorizontalAlignment" Value="Center" />
                    <Setter Property="VerticalAlignment" Value="Center" />
                </Style>
            </DataTemplate.Resources>
            <Image Source="{Binding Path=ImageLocation}" Width="{Binding RenderWidth}" Height="{Binding RenderHeight}" Stretch="Fill" />
        </DataTemplate>

        <DataTemplate x:Key="ToolstringListTemplate">
            <DataTemplate.Resources>
                <Style TargetType="Image">
                    <Setter Property="Width" Value="30" />
                    <Setter Property="Height" Value="30" />
                    <Setter Property="Margin" Value="3" />
                </Style>
            </DataTemplate.Resources>
            <!--<StackPanel>-->
            <Image Source="{Binding Path=ImageLocation}" />
            <!--<TextBlock Text="{Binding Path=Name}" TextAlignment="Center" FontWeight="Bold" />
            </StackPanel>-->
        </DataTemplate>

        <DataTemplate x:Key="ToolWrapTemplate">
            <DataTemplate.Resources>
                <Style TargetType="Image">
                    <Setter Property="Width" Value="70" />
                    <Setter Property="Height" Value="70" />
                    <Setter Property="Margin" Value="15,15,15,3" />
                </Style>
            </DataTemplate.Resources>
            <StackPanel>
                <Image Source="{Binding Path=ImageLocation}" />
                <TextBlock Text="{Binding Name}" HorizontalAlignment="Center" VerticalAlignment="Center" TextWrapping="Wrap" FontSize="10"/>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="planetTemplateDrag">
            <DataTemplate.Resources>
                <Style TargetType="Image">
                    <Setter Property="Width" Value="60" />
                    <Setter Property="Height" Value="60" />
                    <Setter Property="Margin" Value="5" />
                </Style>
            </DataTemplate.Resources>
            <StackPanel>
                <Image Source="{Binding Path=ImageLocation}" />
                <TextBlock Text="{Binding Path=Name}" TextAlignment="Center" FontWeight="Bold" />
            </StackPanel>
        </DataTemplate>

        <ItemsPanelTemplate x:Key="stackTemplate">
            <StackPanel />
        </ItemsPanelTemplate>

        <ItemsPanelTemplate x:Key="wrapTemplate">
            <WrapPanel />
        </ItemsPanelTemplate>

        <DataTemplate x:Key="descriptionTemplate">
            <TextBlock Text="{Binding Path=Description}" TextWrapping="Wrap" FontWeight="Normal" />
        </DataTemplate>

        <DataTemplate x:Key="nameTemplate">
            <TextBlock Text="{Binding Path=Name}" FontWeight="Bold" />
        </DataTemplate>

    </Window.Resources>
    <Grid Margin="10,0,10,10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100" />
            <ColumnDefinition Width="447" />
            <ColumnDefinition Width="35*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="458*" />
        </Grid.RowDefinitions>
        <!--Diagram-->
        <ListView Name="listTS" Background="AliceBlue" Grid.Column="0" ItemsSource="{Binding Path=ToolstringDiagram}" Grid.RowSpan="2" Grid.Row="1" Width="Auto" BorderBrush="Black">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView>
                    <GridViewColumn CellTemplate="{StaticResource ToolstringTemplate}" Header="Toolstring" Width="96" />
                    <!--<ItemsControl Background="AliceBlue" local:DragDropHelper.DragDropTemplate="{StaticResource ToolstringTemplate}" local:DragDropHelper.IsDragSource="true" local:DragDropHelper.IsDropTarget="true" ItemTemplate="{StaticResource ToolstringTemplate}" ItemsPanel="{StaticResource stackTemplate}" ItemsSource="{Binding Path=ToolstringDiagram}" Margin="0" Grid.Row="1" Width="100"></ItemsControl>-->
                </GridView>
            </ListView.View>
        </ListView>
        <!--Toollist-->
        <ListView Name="listTD" BorderBrush="Black" Background="AliceBlue" Grid.Column="1" ItemsSource="{Binding Path=ToolstringDiagram}" Grid.RowSpan="2" Grid.Row="1" Width="Auto"
            local:DragDropHelper.IsDragSource="True" local:DragDropHelper.IsDropTarget="True" 
            local:DragDropHelper.DragDropTemplate="{StaticResource planetTemplateDrag}"
            local:DragDropHelper.PreviewDropFromDiffHandler="{Binding listTD_PreviewDropFromDiffWrapper, ElementName=Main}"
            local:DragDropHelper.PreviewDropToDiffHandler="{Binding listTD_PreviewDropToDiffWrapper, ElementName=Main}" KeyUp="listTD_KeyUp">
            <!--local:DragDrop.IsDragSource="True" dnd:DragDrop.IsDropTarget="True" dnd:DragDrop.DragAdornerTemplate="{StaticResource planetTemplateDrag}" BorderBrush="Black" Name="listTS" Drop="listTS_Drop"
                  dnd:DragDrop.DropHandler="listTS_DropHandler">-->
            <ListView.View>
                <GridView>
                    <GridViewColumn CellTemplate="{StaticResource ToolstringListTemplate}" Header="Tool"/>
                    <GridViewColumn CellTemplate="{StaticResource nameTemplate}" Header="Name" />
                    <GridViewColumn CellTemplate="{StaticResource descriptionTemplate}" Header="Description" />
                </GridView>
            </ListView.View>
        </ListView>
        <!--Add more Tool-->
        <Expander Grid.Column="2" Grid.Row="1" Height="Auto" HorizontalAlignment="Stretch" Name="expander1" VerticalAlignment="Stretch" ExpandDirection="Right" Width="Auto" Grid.ColumnSpan="1" Margin="10,0,0,0" Expanded="expander1_Expanded" Collapsed="expander1_Collapsed">
            <Expander.Header>
                <TextBlock Text="Pick-Up more TOOLs from your Unit : ELU-8434" FontWeight="Bold">
                    <TextBlock.LayoutTransform>
                        <RotateTransform Angle="90" />
                    </TextBlock.LayoutTransform>
                </TextBlock>
            </Expander.Header>
            <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto">
                <ItemsControl Name="wpanelTC" Background="AliceBlue" BorderBrush="Black" BorderThickness="1"
		    ItemsSource="{Binding Path=ToolsCollection}" ItemTemplate="{StaticResource ToolWrapTemplate}" ItemsPanel="{StaticResource wrapTemplate}" Grid.Column="0" Margin="5,0,0,0" 
            local:DragDropHelper.IsDragSource="true" local:DragDropHelper.IsCopy="True"
            local:DragDropHelper.DragDropTemplate="{StaticResource planetTemplateDrag}"/>
                <!--:DragDrop.IsDragSource="True" dnd:DragDrop.IsDropTarget="True" dnd:DragDrop.DragAdornerTemplate="{StaticResource planetTemplateDrag}" BorderBrush="Black" BorderThickness="1" />-->
            </ScrollViewer>
        </Expander>
        <StackPanel Orientation="Horizontal" Grid.ColumnSpan="3" Margin="0">
            <TextBlock Height="Auto" HorizontalAlignment="Center" Margin="0" Name="txtRunNo" Text="Run No. :" VerticalAlignment="Center" />
            <ComboBox Height="23" HorizontalAlignment="Stretch" Margin="10,0,0,0" Name="cbRunNo" VerticalAlignment="Stretch" Width="70" Grid.Column="1" Text="... New Run ..." SelectionChanged="cbRunNo_SelectionChanged">
                <ComboBox.ItemContainerStyle>
                    <Style TargetType="{x:Type ComboBoxItem}">
                        <Setter Property="Foreground" Value="{Binding Foreground}"/>
                    </Style>
                </ComboBox.ItemContainerStyle>
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Number, StringFormat='RUN {0}'}"/>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <TextBlock Height="Auto" Margin="40,0,0,0" Name="txtPreset" Text="Preset :" HorizontalAlignment="Center" VerticalAlignment="Center" />
            <ComboBox Height="23" Margin="10,0,0,0" Name="cbPreset" Width="135" Grid.Column="1" SelectionChanged="cbPreset_SelectionChanged"></ComboBox>
            <Button Content="SAVE" Grid.Column="1" Grid.ColumnSpan="2" Height="23" Name="butSave" Width="70" Margin="40,0,0,0" Foreground="Crimson" Click="butSave_Click" />
            <Button Content="Edit Tool" Height="23" Margin="40,0" Name="butEditTool" Width="70" Grid.Column="1" Grid.ColumnSpan="2" HorizontalAlignment="Right" Click="butEditTool_Click" Foreground="Black" />
        </StackPanel>
    </Grid>
</Window>